#include <std.h>
#include <system.h>
#include <error.h>
#include <type.h>
#include <vbe.h>
#include <memory.h>
#include <asm.h>
#include <ui.h>
#include <textbox.h>

/* This file has functions which link directly to the main ui lfb functions*/

//Textbox handling functions:


#define COLWHI 0xffffff
#define COLRED 0xff0000

#define TEXTX 8
#define TEXTY 10

#define textwidth(text) strlen(text)*8


void draw_textbox(u32 *video,int x,int y,int x1,int y1,char *text)
{
	int tx,ty;
	int grad;
	for(grad=0;grad<5;grad++)	{
		setcolor(((0xff/5)*grad)<<8);
		drawbox(video,x+grad,y+grad,x1-grad,y1-grad);
	}
	paint_block(video,COLWHI,x+4,y+4,x1-4,y1-4);
	x+=4;
	y+=4;
	x1-=4;
	y1-=4;
	setcolor(0);
	for(ty=y+TEXTY;ty<=(y1-TEXTY) && *text!=NULL;ty+=TEXTY)	{
		for(tx=x+TEXTX;tx<=(x1-TEXTX) && *text!=NULL;tx+=TEXTX)	{
			drawfont(video,tx,ty,*text);
			text++;
		}
	}
}

textbox *create_textbox(u32 *video,int x,int y,int x1,int y1,char *text)
{
	textbox *txt;
	txt=(textbox *)get_mem(sizeof(textbox));
	txt->x=x;
	txt->y=y;
	txt->x1=x1;
	txt->y1=y1;
	txt->text=text;
	draw_textbox(video,x,y,x1,y1,text);
	return txt;
}

void move_textbox(u32 *video,textbox *txt,int x,int y,int x1,int y1)
{
	txt->x=x;
	txt->y=y;
	txt->x1=x1;
	txt->y1=y1;
	draw_textbox(video,x,y,x1,y1,txt->text);
}
